﻿$().ready(function () {


    //俱乐部报名表单页，点击'立即报名'时触发
    $("#enrollSendFormButton").click(function () {
        var detailName = $("#detailName").val();
        if (detailName == "") {
            $("#enrollNameMessage").css("visibility", "visible");
            return;
        }

        var email = $("#email").val();
        if (!checkEmail(email)) {
            $("#enrollEmailMessage").css("visibility", "visible");
            return;
        }


        var detailCompanyOrSchool = $("#detailCompanyOrSchool").val();
        if (detailCompanyOrSchool == "") {
            $("#enrollSchoolMessage").css("visibility", "visible");
            return;
        }


        var detailJobTitle = $("#detailJobTitle").val();
        if (detailJobTitle == "") {
            $("#enrollJobMessage").css("visibility", "visible");
            return;
        }

        var phone = $("#phone").val();
        if (!isMobil(phone)) {
            $("#enrollPhoneMessage").css("visibility", "visible");
            return;
        }



        //获取表单数据
        var formData = $("#enrollForm").serialize();

        $.post('/club/enroll', formData, function (responseData) {
            if (responseData.Data == 'ok')
            {
                //报名成功，弹出提示框
                $('#scourse-forbid-dialog').modal('show');


            }
        }, "json");

    });

    $(".enrollFormItemTextInput").focus(function () {
        hideMessagelabel();
    });


    //课程具体内容页面的右下角部分的'换一批'学员按钮点击触发
    $("#scourse-change-students").click(function () {
        getStudentsData();
    });

    $(".modalCloseButton").click(closeDialog);
    $("#scourse-forbid-button").click(closeDialog);


    //课程具体内容页面的右下角部分的'换一批'学员按钮点击触发
    function getStudentsData() {
        $.post("/course/students", { courseID: $("#courseID").val() }, function (data) {
            $("#scourse-student-content").html(data);
        });
    }

    function closeDialog() {
        $("#scourse-forbid-dialog").modal("hide");
    }


    function hideMessagelabel() {
        $("#enrollNameMessage").css("visibility", "hidden");
        $("#enrollEmailMessage").css("visibility", "hidden");
        $("#enrollSchoolMessage").css("visibility", "hidden");
        $("#enrollJobMessage").css("visibility", "hidden");
        $("#enrollPhoneMessage").css("visibility", "hidden");
    }
    function isMobil(phoneNumber) {
        strReg = /^\d{11}$/;
        r = strReg.test(phoneNumber);
        return r;
    }

    function checkEmail(email) {
        strReg = /^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig;
        r = email.search(strReg);
        if (r == -1) {
            return false;
        }
        return true;
    }


    getStudentsData();
});
